const express = require('express')//引入express模块
const path = require('path')//引入路径模块
const DetectUser = require('../js/DetectUser')//引入自定义模块
const router = express.Router()//实例化路由对象
router.get('/', (req, res,next) => {
    let filepath = path.join(__dirname, '../index.html')//绝对路径首页拼接起来
    res.sendFile(filepath)//响应 filepath 路径的文件
})
router.get('/views/login', (req, res ,next) => {
    // console.log(req.params);
    let filepath = path.join(__dirname, '../views/login.html')
    res.send('login ' + req.times)
    next(filepath)
    // res.sendFile(filepath)
})
router.get('/views/register', (req, res,next) => {
    let filepath = path.join(__dirname, '../views/register.html')
    next(filepath)
    // res.sendFile(filepath)
})
router.get('/views/loginp', (req, res) => {
    console.log(req.query);
    res.send(DetectUser.login(req.query))//接受登录url后的参数
    // let filepath= path.join(__dirname,'../views/login.html')
    // res.sendFile(filepath)
})
router.get('/views/registerp', (req, res) => {
    // let filepath= path.join(__dirname,'../views/register.html')
    // res.sendFile(filepath)
    res.send(DetectUser.register(req.query))//接受注册url后的参数
})

router.use( (err,req,res,next)=>{
    // res.send('到达了4个参数的这个中间件')
    res.sendFile(err)
} )

module.exports = router//暴露router对象